package com.ocom.webapi.controller;

import com.ocom.common.constant.WebApiServiceUrl;
import com.ocom.common.resp.Result;
import com.ocom.webapi.service.SmsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

//@Log4j
@RestController
//@PreAuthorize("@pms.hasRole('ROLE_WEB')" )
public class SmsController {
    private final Logger log = LoggerFactory.getLogger(SmsController.class);

    //短信业务
    @Autowired
    private SmsService smsService;


    /**
     * 短信验证码（/smsCode）
     */
    @PostMapping(WebApiServiceUrl.URL_SmsCode)
    public Result SmsCode(@RequestBody Map map){
        String phone = (String) map.get("phone");
        log.info("短信验证码请求参数：{{}}",phone);
        return smsService.SmsCode(phone);
    }

    /**
     * 登录后获取单位范围(/companyGroup)
     * */
    @PostMapping(WebApiServiceUrl.URL_CompanyGroup)
    public Result CompanyGroup(@RequestBody Map map){
        log.info("登录后获取单位范围请求参数：{{}}",map);
        return smsService.CompanyGroup(map);
    }

    /**
     * 验证短信 (/checkSmsCode)
     * */
    @PostMapping(WebApiServiceUrl.URL_checkSmsCode)
    public Result checkSmsCode(@RequestBody Map map){
        log.info("验证短信请求参数：{{}}",map);
        return smsService.checkSmsCode(map);
    }

}
